Hello, I hope you can help me with a question.
I have a panel data with variables year, firm, industry, weight and indepvar.
For each observation i, I want to find out what is the weighted average of indepvar for the industry of the observation i, by year,but removing that firm i from the calculation of the weighted average of indepvar. The idea here is to have a weighted average of indepvar for the particular industry of firm i, in a given year, but pretending firm i is not part of that Industry. The weighted average must pretend firm i is not part of that industry.
I know how to create the weighted average of indepvar by year by industry:
bys year industry: asgen weighted_average_IndepVar = indepvar, w(weight)
But that is how it should not be. This code includes frim i in the calculation of the weighted average indepvar by industry by year.
I do not know how to exclude the current observation i from the calculation.
I'm attaching a pet data file that shows what the weighted average should and should not be.
(The original dataset I'm working on has over 50 thousand firms, so creating flag columns for each firm is not really an option).
I really appreciate any help.
Thanks so much!
Lucas B.
I have a panel data with variables year, firm, industry, weight and indepvar.
For each observation i, I want to find out what is the weighted average of indepvar for the industry of the observation i, by year,but removing that firm i from the calculation of the weighted average of indepvar. The idea here is to have a weighted average of indepvar for the particular industry of firm i, in a given year, but pretending firm i is not part of that Industry. The weighted average must pretend firm i is not part of that industry.
I know how to create the weighted average of indepvar by year by industry:
bys year industry: asgen weighted_average_IndepVar = indepvar, w(weight)
But that is how it should not be. This code includes frim i in the calculation of the weighted average indepvar by industry by year.
I do not know how to exclude the current observation i from the calculation.
I'm attaching a pet data file that shows what the weighted average should and should not be.
(The original dataset I'm working on has over 50 thousand firms, so creating flag columns for each firm is not really an option).
I really appreciate any help.
Thanks so much!
Lucas B.
Comment